
#line 1 "..\..\main.c" /0
 
 
 
 
 
  
#line 1 "D:\6.Embed\61-KEIL-ARM\C51\INC\reg52.h" /0






 
 
 
 
 
 
 sfr P0    = 0x80;
 sfr P1    = 0x90;
 sfr P2    = 0xA0;
 sfr P3    = 0xB0;
 sfr PSW   = 0xD0;
 sfr ACC   = 0xE0;
 sfr B     = 0xF0;
 sfr SP    = 0x81;
 sfr DPL   = 0x82;
 sfr DPH   = 0x83;
 sfr PCON  = 0x87;
 sfr TCON  = 0x88;
 sfr TMOD  = 0x89;
 sfr TL0   = 0x8A;
 sfr TL1   = 0x8B;
 sfr TH0   = 0x8C;
 sfr TH1   = 0x8D;
 sfr IE    = 0xA8;
 sfr IP    = 0xB8;
 sfr SCON  = 0x98;
 sfr SBUF  = 0x99;
 
 
 
 sfr T2CON  = 0xC8;
 sfr RCAP2L = 0xCA;
 sfr RCAP2H = 0xCB;
 sfr TL2    = 0xCC;
 sfr TH2    = 0xCD;
 
 
 
 
 sbit CY    = PSW^7;
 sbit AC    = PSW^6;
 sbit F0    = PSW^5;
 sbit RS1   = PSW^4;
 sbit RS0   = PSW^3;
 sbit OV    = PSW^2;
 sbit P     = PSW^0;  
 
 
 sbit TF1   = TCON^7;
 sbit TR1   = TCON^6;
 sbit TF0   = TCON^5;
 sbit TR0   = TCON^4;
 sbit IE1   = TCON^3;
 sbit IT1   = TCON^2;
 sbit IE0   = TCON^1;
 sbit IT0   = TCON^0;
 
 
 sbit EA    = IE^7;
 sbit ET2   = IE^5;  
 sbit ES    = IE^4;
 sbit ET1   = IE^3;
 sbit EX1   = IE^2;
 sbit ET0   = IE^1;
 sbit EX0   = IE^0;
 
 
 sbit PT2   = IP^5;
 sbit PS    = IP^4;
 sbit PT1   = IP^3;
 sbit PX1   = IP^2;
 sbit PT0   = IP^1;
 sbit PX0   = IP^0;
 
 
 sbit RD    = P3^7;
 sbit WR    = P3^6;
 sbit T1    = P3^5;
 sbit T0    = P3^4;
 sbit INT1  = P3^3;
 sbit INT0  = P3^2;
 sbit TXD   = P3^1;
 sbit RXD   = P3^0;
 
 
 sbit SM0   = SCON^7;
 sbit SM1   = SCON^6;
 sbit SM2   = SCON^5;
 sbit REN   = SCON^4;
 sbit TB8   = SCON^3;
 sbit RB8   = SCON^2;
 sbit TI    = SCON^1;
 sbit RI    = SCON^0;
 
 
 sbit T2EX  = P1^1;  
 sbit T2    = P1^0;  
 
 
 sbit TF2    = T2CON^7;
 sbit EXF2   = T2CON^6;
 sbit RCLK   = T2CON^5;
 sbit TCLK   = T2CON^4;
 sbit EXEN2  = T2CON^3;
 sbit TR2    = T2CON^2;
 sbit C_T2   = T2CON^1;
 sbit CP_RL2 = T2CON^0;
 
 
#line 6 "..\..\main.c" /0
 
  
#line 1 "D:\6.Embed\61-KEIL-ARM\C51\INC\stdio.h" /0






 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 typedef unsigned int size_t;
 
 
 #pragma SAVE
 #pragma REGPARMS
 extern char _getkey (void);
 extern char getchar (void);
 extern char ungetchar (char);
 extern char putchar (char);
 extern int printf   (const char *, ...);
 extern int sprintf  (char *, const char *, ...);
 extern int vprintf  (const char *, char *);
 extern int vsprintf (char *, const char *, char *);
 extern char *gets (char *, int n);
 extern int scanf (const char *, ...);
 extern int sscanf (char *, const char *, ...);
 extern int puts (const char *);
 
 #pragma RESTORE
 
 
 
#line 7 "..\..\main.c" /0
 


 
 
 
 typedef unsigned int uint;	 
 typedef unsigned char uchar;
 
 
 sfr T2MOD = 0xC9;
 
 sbit S4 = P3^3;
 sbit S5 = P3^2;
 sbit S6 = P3^1;
 sbit S7 = P3^0;
 
 enum PERIPHERAL
 {
 LED = 0x80,
 DEVICE = 0xa0,
 BIT = 0xc0,
 SEG = 0xe0
 };
 
 typedef enum
 {
 UNPRESS = 0, 
 S4_PRESS = 4, 
 S5_PRESS, 
 S6_PRESS, 
 S7_PRESS 
 }KeyEvent_TypeDef;


 
 
 uchar Dsp_Bit[16] = {0};
 
 uchar Dsp_Code[8] = {0};
 
 uint	Tick;
 
 uchar 	Num1,Num2;
 bit		Para;
 
 
 
 





 
 void Timer2_Init(void)		 
 {
 T2MOD = 0;				 
 T2CON = 0;				 
 TL2 = 0x18;				 
 TH2 = 0xFC;				 
 RCAP2L = 0x18;			 
 RCAP2H = 0xFC;			 
 TR2 = 1;				 
 TF2 = 0;
 
 ET2 = 1;
 EA = 1;
 }
 
 





 
 void Timer2_Rountine() interrupt 5           
 {
 static uchar dsp_com;
 TF2 = 0;				 
 
 Tick++;		
 
  P0=0;P2=BIT;P2=0;									 
  P0=Dsp_Code[dsp_com];P2=SEG;P2=0;		 
  P0=1 << (dsp_com);P2=BIT;P2=0;				 
 if(++dsp_com > 7)								 
 dsp_com = 0;
 }
 





 
 void Seg_Tran(void)
 {
 unsigned char i, j=0, temp;
 for (i=0; i<8; i++, j++)
 {
 switch (Dsp_Bit[j]) 
 {  
 case '0': temp = 0xc0; break;
 case '1': temp = 0xf9; break;
 
 case '2': temp = 0xa4; break;
 case '3': temp = 0xb0; break;
 
 case '4': temp = 0x99; break;
 
 case '5': temp = 0x92; break;
 case '6': temp = 0x82; break;
 
 case '7': temp = 0xf8; break;
 
 case '8': temp = 0x80; break;
 case '9': temp = 0x90; break;
 
 case 'A': temp = 0x88; break;
 case 'B': temp = 0x83; break;
 case 'C': temp = 0xc6; break;
 case 'D': temp = 0xA1; break;
 case 'E': temp = 0x86; break;
 case 'F': temp = 0x8E; break;
 case 'H': temp = 0x89; break;
 case 'L': temp = 0xC7; break;
 case 'N': temp = 0xC8; break;
 case 'P': temp = 0x8c; break;
 case 'U': temp = 0xC1; break;
 case '-': temp = 0xbf; break;
 case ' ': temp = 0xff; break;
 case '^': temp = 0xfe; break;  
 case '_': temp = 0xf7; break;  
 default: temp = 0xff;
 }
 if (Dsp_Bit[j+1] == '.')
 {
 temp = temp&0x7f;              
 j++;
 }
 Dsp_Code[i] = temp;
 }
 }
 
 
 








 
 KeyEvent_TypeDef KeyScan(void)
 {
 
 static uchar S4_value = 0xFF;
 static uchar S5_value = 0xFF;
 static uchar S6_value = 0xFF;
 static uchar S7_value = 0xFF;
 static uchar lock = 0;
 
 
 
 S4_value <<= 1;
 S4_value |= S4;
 S5_value <<= 1;
 S5_value |= S5;
 S6_value <<= 1;	
 S6_value |= S6;
 S7_value <<= 1;
 S7_value |= S7;
 
 if((!S4_value||!S5_value||!S6_value||!S7_value) && !lock)	 
 {
 lock = 1;				 
 if(!S4_value)
 return S4_PRESS;
 else if(!S5_value)
 return S5_PRESS;
 else if(!S6_value)
 return S6_PRESS;
 else if(!S7_value)
 return S7_PRESS;
 }
 else if(S4_value && S5_value && S6_value && S7_value && lock)			 
 {
 lock = 0;													
 }
 else{																	 
 }
 
 return UNPRESS;  
 }





 
 void Key_Task(void)
 {
 static uint Key_Tick;							
 
 if((Tick - Key_Tick) > 2)
 {
 Key_Tick = Tick;
 switch (KeyScan())
 {
 case UNPRESS:
 break;
 case S7_PRESS:
 Para = !Para;		 
 break;
 case S6_PRESS:			 
 if(!Para)
 {
 if(++Num1>23)
 Num1 = 0;
 }
 else
 {
 if(++Num2>59)
 Num2 = 0;		
 }				
 break;
 case S5_PRESS:			 
 if(!Para)
 {
 if(--Num1>23)
 Num1 = 23;
 }
 else
 {
 if(--Num2>59)
 Num2 = 59;		
 }	
 break;
 case S4_PRESS:
 if(!Para)
 Num1 = 0;
 else
 Num2 = 0;
 break;
 default:
 break;
 }			
 }
 }	





 
 void Display_Task(void)
 {
 static uchar Display_Tick;
 
 if((Tick - Display_Tick) > 500)
 {	
 Display_Tick = Tick;
 
 if(!Para)
 {
 sprintf(Dsp_Bit, "A-%2uB %2u", (uint)Num1, (uint)Num2);
 }
 else
 {
 sprintf(Dsp_Bit, "A %2uB-%2u", (uint)Num1, (uint)Num2);			
 }
 }
 Seg_Tran();
 }
 
 
 





 
 void LED_Flow_Task(void)
 {
 static uint LED_Tick;
 static uchar State = 0;
 
 if((Tick - LED_Tick) > 500)
 {	
 LED_Tick = Tick;
 
 switch (State)                 
 {
 case 0:
  P0=~(1<<State);P2=LED;P2=0;
  P0=1<<4;P2=DEVICE;P2=0;
 State = 1;
 break;
 case 1:
  P0=~(1<<State);P2=LED;P2=0;
  P0=0x00;P2=DEVICE;P2=0;
 State = 2;
 break;
 case 2:
  P0=~(1<<State);P2=LED;P2=0;
  P0=0x00;P2=DEVICE;P2=0;
 State = 3;            
 break;
 case 3:
  P0=~(1<<State);P2=LED;P2=0;
  P0=0x00;P2=DEVICE;P2=0;
 State = 4;    
 break;
 case 4:
  P0=~(1<<State);P2=LED;P2=0;
  P0=1<<6;P2=DEVICE;P2=0;
 State = 5;
 break;
 case 5:
  P0=~(1<<State);P2=LED;P2=0;
  P0=0x00;P2=DEVICE;P2=0;
 State = 6;
 break;
 case 6:
  P0=~(1<<State);P2=LED;P2=0;
  P0=0x00;P2=DEVICE;P2=0;
 State = 7;
 break;
 case 7:
  P0=~(1<<State);P2=LED;P2=0;
  P0=0x00;P2=DEVICE;P2=0;
 State = 0;
 break;
 default:
 break;	
 }
 }
 }
 





 
 void P_Init(void)				 
 {
  P0=0xff;P2=LED;P2=0;
  P0=0x00;P2=DEVICE;P2=0;
  P0=0x00;P2=BIT;P2=0;
  P0=0xff;P2=SEG;P2=0;
 
 Timer2_Init(); 
 }
 


 
 void main(void)
 {
 
 P_Init();
 
 
 while(1)
 {
 LED_Flow_Task();
 Key_Task();
 Display_Task();
 }        
 }
